import pandas as pd
from pyecharts.charts import Bar
from pyecharts import options as opts
# 读取CSV文件
df = pd.read_csv('../csv/tag_like_1.csv', usecols=['like_count'])
# 将字符串元素转换为整数
for col in df.columns:
    df[col] = df[col].astype(int)
# 统计不同范围的元素数量
count_dict = {'1-500': 0, '501-1000': 0, '1000-2000': 0, 'Above 2000': 0}
for value in df.values:
    if 1 <= value <= 500:
        count_dict['1-500'] += 1
    elif 501 <= value <= 1000:
        count_dict['501-1000'] += 1
    elif 1000 <= value <= 2000:
        count_dict['1000-2000'] += 1
    elif value > 2000:
        count_dict['Above 2000'] += 1
# 输出结果
for range, count in count_dict.items():
    print(f"范围 {range}: {count} 个元素")


def make_bar_4():
    bar = Bar()
    bar.add_xaxis(['点赞数达到1-500的作品数', '点赞数达到501-1000的作品数', '点赞数达到1001-2000的作品数', '点赞数超过2000的作品数'])
    bar.add_yaxis("作品数", [619, 294, 163, 168])
    bar.set_global_opts(
        xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-15)),
        title_opts=opts.TitleOpts(title="标签点赞数范围统计"),
        datazoom_opts=[opts.DataZoomOpts(range_start=0, range_end=200, orient="horizontal")]
    )
    bar.render('../html/标签点赞数范围统计.html')
    return bar
if __name__ == "__main__":
    make_bar_4()

